Overview
Duet’s shared terminal provides a fully synchronized shell environment where all participants see exactly the same output in real time. Every keystroke, command, and output is instantly visible to everyone in the session.How it works
The terminal is built on three key technologies:PTY
Pseudoterminal provides a real shell process with full terminal capabilities
VT10x
Terminal emulator handles ANSI escape sequences, colors, and cursor positioning
Pub/Sub
Subscriber pattern broadcasts updates to all connected clients
Terminal initialization
When a room is created, Duet starts a shell in an isolated workspace:Each room gets its own shell process running in
/app/workspaces/{workspace-name}. This provides complete isolation between sessions.Real-time synchronization
Duet uses a subscriber pattern to keep all participants in sync:1
Input from any client
When you type in the terminal, your keystrokes are sent directly to the PTY:
2
PTY processes the input
The shell receives the input and generates output (stdout/stderr).
3
VT10x parses the output
A background read loop feeds PTY output into the VT10x emulator:
4
All clients re-render
Each connected client receives a notification and renders the updated terminal state.
Rendering optimization
Duet minimizes CPU usage with smart caching:- Performance
- Color support
- Caching: Only re-renders when PTY output changes (dirty flag)
- Run-length encoding: ANSI color codes only emitted when colors change
- Efficient broadcast: Non-blocking channel sends to all subscribers
Window resizing
When your terminal window changes size, Duet automatically adjusts:Typing indicators
Duet shows when other participants are actively typing:Cursor rendering
The cursor position is synchronized across all clients using reverse video:Terminal lifecycle
Supported features
Full shell interaction
Full shell interaction
- Execute any shell command
- Run interactive programs (vim, htop, etc.)
- Tab completion
- Command history (arrow keys)
- Job control (Ctrl+C, Ctrl+Z)
ANSI escape sequences
ANSI escape sequences
- Cursor movement (\x1b[A, \x1b[B, etc.)
- Text styling (bold, italic, underline)
- 256-color palette
- Clear screen / line
- Save/restore cursor position
Special keys
Special keys
All keyboard input is properly mapped:
- Arrow keys →
\x1b[Athrough\x1b[D - Home/End →
\x1b[H/\x1b[F - Backspace → ASCII 127
- Delete →
\x1b[3~ - Tab →
\t - Enter →
\r
Workspace isolation
Each room operates in its own directory:Workspaces are completely isolated. You can create files, install packages, and run processes without affecting other rooms. Everything is cleaned up when the session ends.
Limitations
Next steps
AI assistant
Get AI-powered help while coding in the shared terminal
Sandbox execution
Run isolated commands using Cloudflare Sandboxes